package com.ymatou.iapi.godmch.testcase;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getMchConfigBean;
import com.ymatou.iapi.godmch.parameter.setMchAllConfigBean;
import com.ymatou.iapi.godmch.parameter.setShareTypeBean;
import com.ymatou.iapi.godmch.service.getMchConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodmchSubscriptionService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.afterserviceinfo;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
/**
*商户配置信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMchConfig{
	private static getMchConfigBean bean;
	private static getMchConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户配置信息");
	}

	@Before
	public void caseUp() {
		bean=new getMchConfigBean();
		call=new getMchConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_001() {
		Logger.start(true,"正例-商户配置信息");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			GodmchManageCallService.SetWaterMark(mchId);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFill(), "验证ProductPicAutoFill");
			Logger.verifyEquals(DB_info.getShoppingNotice(), return_info.getShoppingNotice(), "验证ShoppingNotice");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_001_2() {
		Logger.start(true,"正例-商户配置信息-shoppingNotice有数据");
		try {
//			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
//			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
//			
//			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
//			GodmchManageCallService.createmchCallForChannel(createmchBean);
//			GodmchManageCallService.SetWaterMark(mchId);
//			
			//bean.setMchId(mchId);
			bean.setMchId(501005715);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFill(), "验证ProductPicAutoFill");
			Logger.verifyEquals(DB_info.getShoppingNotice(), return_info.getShoppingNotice(), "验证ShoppingNotice");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_001_1() {
		Logger.start(true,"正例-商户配置信息-开启图片补白功能");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			GodmchManageCallService.SetWaterMark(mchId);
			
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId);
			setShareTypeBean.setProductPicAutoFill(true);
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFillEnabled(), "验证ProductPicAutoFill");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_002() {
		Logger.start(true,"正例-商户配置信息-mch_config没有数据时 默认 mchSideBuy=2 20200309");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			GodmchManageCallService.SetWaterMark(mchId);
			
			bean.setMchId(500000004);
			call.setData(bean);
			call.callService();	
			

			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
			Logger.verifyEquals(2, return_info.getMchSideBuy(), "验证MchSideBuy");
	    	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_003() {
		Logger.start(true,"正例-商户配置信息-开通线下支付(godmch 调 曹二信服务)");
		try {

//			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();	
//			GodmchSubscriptionService.ApplyCharge(mchId, 4, 5);
//			GodmchManageCallService.SetTrueMchChargeConfig(mchId, Arrays.asList(4),true);
		
			//bean.setMchId(mchId);
			//bean.setMchId(501005715);
			bean.setMchId(501078776);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			//Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFill(), "验证ProductPicAutoFill");
			Logger.verifyEquals(DB_info.getShoppingNotice(), return_info.getShoppingNotice(), "验证ShoppingNotice");
			//新增 20200612
			Logger.verifyEquals(true, return_info.getOfflineCollection(), "验证OfflineCollection");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_004() {
		Logger.start(true,"正例-商户配置信息-不开通线下支付(godmch 调 曹二信服务)");
		try {

			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();	
//			GodmchSubscriptionService.ApplyCharge(mchId, 4, 5);
//			GodmchManageCallService.SetTrueMchChargeConfig(mchId, Arrays.asList(4),true);
		
			bean.setMchId(mchId);
			//bean.setMchId(501005715);
			//bean.setMchId(501078776);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			//Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFill(), "验证ProductPicAutoFill");
			Logger.verifyEquals(DB_info.getShoppingNotice(), return_info.getShoppingNotice(), "验证ShoppingNotice");
			//新增 20200612
			Logger.verifyEquals(false, return_info.getOfflineCollection(), "验证OfflineCollection");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchConfig_005() {
		Logger.start(true,"正例-商户配置信息-设置商家是否可以设置会员注册条款-返回成功-新增2020623");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			GodmchManageCallService.SetWaterMark(mchId);
			
			//	商家是否可以设置会员注册条款
			Map<String,Object> map=new HashMap();
			map.put("regTerm", true);
			GodmchManageCallService.setMchAllConfig(mchId, map);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			
			mch_configWapper wapper=new mch_configWapper();
			mch_configExample example=new mch_configExample();
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
		    mch_config DB_info=wapper.selectByExample(example).get(0);
			
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	mch_config return_info=call.getResult();
	    	
			Logger.verifyEquals(DB_info.getRegTerm(), return_info.getRegTerm(), "验证RegTerm");
			Logger.verifyEquals(true, return_info.getRegTerm(), "验证RegTerm");
			
			Logger.verifyEquals(DB_info.getWaterMark(), return_info.getWaterMark(), "验证WaterMark");
			Logger.verifyEquals(DB_info.getAgentWaterMark(), return_info.getAgentWaterMark(), "验证AgentWaterMark");
			Logger.verifyEquals(DB_info.getOfflineCollection(), return_info.getOfflineCollection(), "验证OfflineCollection");
			Logger.verifyEquals(DB_info.getOptionalIdCard(), return_info.getOptionalIdCard(), "验证OptionalIdCard");
			Logger.verifyEquals(DB_info.getProductPicAutoFill(), return_info.getProductPicAutoFill(), "验证ProductPicAutoFill");
			Logger.verifyEquals(DB_info.getShoppingNotice(), return_info.getShoppingNotice(), "验证ShoppingNotice");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}